namespace Glue.Internals.PrintTool
{
    internal class ReportLine
    {

        public ReportLine(IRelation relation)
        {
            LeftSidePropertyName = GetMemberName(relation.LeftMember);
            RightSidePropertyName = GetMemberName(relation.RightMember);
            Direction = relation.Direction;
        }

        public ReportLine(IRelation relation, string leftPropertyPrefix, string rightPropertyPrefix):this(relation)
        {
            LeftSidePropertyName = leftPropertyPrefix + LeftSidePropertyName;
            RightSidePropertyName = rightPropertyPrefix + RightSidePropertyName;
        }

        public string LeftSidePropertyName { get; private set; }

        public string RightSidePropertyName { get; private set; }

        public RelationDirection Direction { get; private set; }

        private string GetMemberName(IObjectMember member)
        {
            if (member.GetParentProperty().HasValue())
                return member.Name.Substring(member.Name.IndexOf(".") + 1);
            return member.Name;

        }
    }
}